package cn.com.callback


import cn.com.elite.EliteBean
import org.apache.commons.logging.Log
import org.apache.commons.logging.LogFactory
import org.json.JSONException

import javax.servlet.http.HttpServletRequest
import javax.servlet.http.HttpServletResponse

/**
 *
 * @Title: apiHST_Data_archiving
 * @Description: 华盛通 每天凌晨历史 数据归档
 * @author: chieh
 * @date 2022-03-21 12:50
 *
 */

public class apiHST_Data_archiving implements ServiceBackInvoke{
	private static final Log log = LogFactory.getLog(apiHST_Data_archiving.class);
	public String doCallBack(EliteBean eliteBean,HttpServletRequest request,HttpServletResponse response) {

		try {
			log.debug("=================state 开始  apiHST_Data_archiving===========" );

			//elitethread线程表归档7天的数据
			String[] data1=new String[4];
			data1[0] = "insert into elitethread_his select * from  elitethread  where 1=1  and createdate<DATE_SUB(CURDATE(), INTERVAL 7 DAY)";
			data1[1] = "delete from  elitethread  where 1=1  and createdate<DATE_SUB(CURDATE(), INTERVAL 7 DAY)";
			data1[2] = "INSERT INTO elitethread(thread_guid, createdate, status, content, type) VALUES (UUID(),NOW(), '2', '在线监控数据汇总', 'autoOnLineMonitor')";
			data1[3] = "INSERT INTO elitethread(thread_guid, createdate, status, content, type) VALUES (UUID(),NOW(), '2', '我的接待数据汇总', 'autoReceptionMonitor')";

			log.debug("elitethread-sq;:" + data1.toString());
			int[] dataresult1 = eliteBean.updateBatch(data1, "dataSource");
			log.debug("elitethread-结果:" + dataresult1.toString());

			//account_information线程表归档7天的数据
			String[] data2=new String[2];
			data2[0] = "insert into account_information_his select * from account_information where createtime<DATE_SUB(CURDATE(), INTERVAL 7 DAY)";
			data2[1] = "delete from account_information where createtime<DATE_SUB(CURDATE(), INTERVAL 7 DAY)";

			log.debug("account_information-sq;:" + data2.toString());
			int[] dataresult2 = eliteBean.updateBatch(data2, "dataSource");
			log.debug("account_information-结果:" + dataresult2.toString());

			//account_information_batch线程表归档7天的数据
			String[] data3=new String[2];
			data3[0] = "insert into account_information_batch_his select * from  account_information_batch  where 1=1  and createdate<DATE_SUB(CURDATE(), INTERVAL 7 DAY)";
			data3[1] = "delete from  account_information_batch  where 1=1  and createdate<DATE_SUB(CURDATE(), INTERVAL 7 DAY)";

			log.debug("account_information_batch-sq;:" + data3.toString());
			int[] dataresult3 = eliteBean.updateBatch(data3, "dataSource");
			log.debug("account_information_batch-结果:" + dataresult3.toString());

			//hst_leadsnotice 提醒消息表归档31天的数据
			String[] data4=new String[2];
			data4[0] = "insert into hst_leadsnotice_his select * from  hst_leadsnotice  where 1=1 and createddate<DATE_SUB(CURDATE(), INTERVAL 3 month)";
			data4[1] = "delete from  hst_leadsnotice  where 1=1  and createddate<DATE_SUB(CURDATE(), INTERVAL 3 month)";

			log.debug("hst_leadsnotice_his-sq;:" + data4.toString());
			int[] dataresult4 = eliteBean.updateBatch(data4, "dataSource");
			log.debug("hst_leadsnotice_his-结果:" + dataresult4.toString());

			//Account_Information_Deposit线程表归档7天的数据
			String[] data5=new String[2];
			data5[0] = "insert into Account_Information_Deposit_his select * from Account_Information_Deposit where createtime<DATE_SUB(CURDATE(), INTERVAL 7 DAY)";
			data5[1] = "delete from Account_Information_Deposit where createtime<DATE_SUB(CURDATE(), INTERVAL 7 DAY)";

			log.debug("account_information-sq;:" + data5.toString());
			int[] dataresult5 = eliteBean.updateBatch(data5, "dataSource");
			log.debug("Account_Information_Deposit-结果:" + dataresult5.toString());

			log.debug("=================end 结束  apiHST_Data_archiving===========" );
			return "{\"code\":\"1\",\"message\":\"成功\",\"data\":{\"endabled\":\"凌晨历史数据归档\"}}";
		} catch (JSONException e) {
			log.error( "处理异常，失败：" + e.getMessage());
		}
	}

}